<?php
namespace app\admin\controller;

use think\Db;
use think\Request;
use think\Session;
use think\Cache;
use think\Controller;
use think\captcha\Captcha;

class Set extends Common
{
    //加载菜单列表
    public function menu()
    {
        $access_token = input('access_token');
        if (session('qm_ad_uid') > 0 && $access_token > 0 && session('qm_ad_uid') == $access_token) {
           $data= '{
 "data": [
        {
            "name": "home",
            "title": "主页",
            "icon": "layui-icon-home",
            "list": [
                {
                    "name": "homepage2",
                    "title": "主页一",
                    "jump": "home/homepage2"
                }
            ]
        },
        {
            "name": "video",
            "title": "视频系统",
            "icon": "layui-icon-video",
            "list": [
                {
                    "name": "video_small",
                    "title": "视频列表",
                    "jump": "video/video_small"
                }
            ]
        }
    ],
    "code": 0,
    "msg": "ok"
}';
        } else {
            $result['code'] = 0;
            $result['msg'] = 'ok';
            $result['data'] = array();
            $data = json_encode($result);
            $data = str_replace('null', '""', $data);
        }
        echo $data;
    }

    public function get_menu()
    {
        $grandpa_list = Db::name('menu')->field('id,title,grandpa_id')->where(array('grandpa_id' => 0, 'status' => 1))->order('sort asc')->select();
        if ($grandpa_list) {
            foreach ($grandpa_list as $k => $v) {
                $parent_list = Db::name('menu')->field('id,title,grandpa_id')->where(array('grandpa_id' => $grandpa_list[$k]['id'], 'parent_id' => 0, 'status' => 1))->order('sort asc')->select();
                $grandpa_list[$k]['list'] = $parent_list;
                foreach ($parent_list as $key => $val) {
                    $son_list = Db::name('menu')->field('id,title,grandpa_id')->where(array('parent_id' => $parent_list[$key]['id']))->order('sort asc')->select();
                    $grandpa_list[$k]['list'][$key]['list'] = $son_list;
                }
            }
        } else {
            $grandpa_list = array();
        }

        $result['code'] = 0;
        $result['msg'] = 'ok';
        $result['data'] = $grandpa_list;
        $data = json_encode($result);
        $data = str_replace('null', '""', $data);
        echo $data;
    }

    //判断会员是否有权限进入页面
    public function check_menu()
    {
        $url = input('post.url');
        $status = 2;
        if ($url && $url == 'user/login') {
            $status = 1;
        } else {
            $status = 1;
        }


        $result['code'] = 0;
        $result['msg'] = 'ok';
        $result['status'] = $status;
        $data = json_encode($result);
        $data = str_replace('null', '""', $data);
        echo $data;
    }

    //判断是否登录
    public function check_login()
    {
        $status = 2;
        if (session('qm_ad_uid')) {
            $status = 1;
        }
        $result['code'] = 0;
        $result['msg'] = 'ok';
        $result['status'] = $status;
        $data = json_encode($result);
        $data = str_replace('null', '""', $data);
        echo $data;
    }
}
